package com.zhm.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhm.demo.controller.req.*;
import com.zhm.demo.controller.res.EmqxHookAuthResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/demo/emqx/hook")
public class EmqxHookController {

    @GetMapping("a")
    public String a() {
        return "123";
    }

    @PostMapping(value = "auth")
    public EmqxHookAuthResDTO auth(@RequestBody EmqxHookAuthReqDTO req) {
        log.info("{}", req);
        EmqxHookAuthResDTO emqxHookAuthResDTO = new EmqxHookAuthResDTO();
        emqxHookAuthResDTO.setResult("allow");
        return emqxHookAuthResDTO;
    }


    @RequestMapping("event")
    public String event(@RequestBody String s) {
        System.out.println(s);
        JSONObject jsonObject = JSONObject.parseObject(s);
        if (jsonObject.getString("event").equals(EmqxHookConnectReq.EVENT)) {
            EmqxHookConnectReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookConnectReq.class);
        }
        if (jsonObject.getString("event").equals(EmqxHookDisconnectReq.EVENT)) {
            EmqxHookDisconnectReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookDisconnectReq.class);
        }
        if (jsonObject.getString("event").equals(EmqxHookEventPublicReq.EVENT)) {
            EmqxHookEventPublicReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookEventPublicReq.class);
        }
        if (jsonObject.getString("event").equals(EmqxHookMsgDropReq.EVENT)) {
            EmqxHookMsgDropReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookMsgDropReq.class);
        }
        if (jsonObject.getString("event").equals(EmqxHookPublicCheckReq.EVENT)) {
            EmqxHookPublicCheckReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookPublicCheckReq.class);
        }
        if (jsonObject.getString("event").equals(EmqxHookPublicMsgReq.EVENT)) {
            EmqxHookPublicMsgReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookPublicMsgReq.class);
        }
        if (jsonObject.getString("event").equals(EmqxHookSubscribeCheckReq.EVENT)) {
            EmqxHookSubscribeCheckReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookSubscribeCheckReq.class);
        }
        if (jsonObject.getString("event").equals(EmqxHookSubscribeReq.EVENT)) {
            EmqxHookSubscribeReq req = JSONObject.parseObject(jsonObject.toJSONString(), EmqxHookSubscribeReq.class);
        }
        return s;
    }
}
